package com.caits.lbs.framework.services.redis;

import org.springframework.data.redis.connection.RedisClusterConfiguration;
import org.springframework.data.redis.connection.RedisNode;

import java.util.HashSet;
import java.util.Set;

/**
 * RedisClusterConfig
 * redisCluster配置支持节点书写方式：host1:port1,host2:port2...
 * @author zhangzhiheng
 * @date 2017/4/11
 */
public class RedisClusterConfig extends RedisClusterConfiguration {
    private String nodes;

    public RedisClusterConfig(String nodes){
        this.nodes = nodes;
        String[] cns = nodes.split(",");
        Set<RedisNode> clusterSet = new HashSet<RedisNode>();
        for(String s: cns) {
            RedisNode node = new RedisNode(s.split(":")[0],Integer.parseInt(s.split(":")[1]));
            clusterSet.add(node);
        }
        super.setClusterNodes(clusterSet);
    }

    public String getNodes() {
        return nodes;
    }

    public void setNodes(String nodes) {
        this.nodes = nodes;
    }
}
